#!/bin/sh
TOMCAT_NAME=tomcat-analytics
TOMCAT_HOME=/home/aisys/tomcat/$TOMCAT_NAME

usage="{stop|start|restart}"

start(){
	echo "Starting $TOMCAT_NAME..."
	$TOMCAT_HOME/bin/startup.sh
	#tail -f $TOMCAT_HOME/logs/catalina.out
}

stop(){
	echo "Stoping $TOMCAT_NAME..."
	$TOMCAT_HOME/bin/shutdown.sh
	PID=`ps -ef |grep $TOMCAT_NAME |grep -v 'grep'|awk '{print $2}'`
	if [ !$PID ] 
	then
		kill -9 $PID
		rm -rf $TOMCAT_HOME/logs/*
	fi
	echo "$TOMCAT_NAME has stoped!"
}

restart(){
	stop
	echo "------------------------------------"
	start
}

#  read arg   
case $1 in  
start)  start;;  
stop)  stop;;  
restart)  restart;;  
*) echo " please input :$usage"  
esac  